//
//  RewardVC.m
//  BasePorject_App
//
//  Created by Yutian Duan on 2019/5/27.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "ResidenceVC.h"
#import "SettingVC.h"
#import "LoginVC.h"
#import "RegistVC.h"
#import "ResidenceTableView.h"
#import "ResidenceHeaderView.h"

@interface ResidenceVC () <ResidenceHeadDelegate>

//@property (nonatomic, strong) ResidenceScrollView *contentView;

@property (nonatomic, strong) ResidenceTableView *tableView;
@property (nonatomic, strong) ResidenceHeaderView *headerView;
@property (nonatomic, strong) NSMutableArray *dataArray;


@end

@implementation ResidenceVC

- (ResidenceHeaderView *)headerView {
  if (!_headerView) {
    _headerView = [[ResidenceHeaderView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
    _headerView.delegate = self;
  }
  return _headerView;
}

- (ResidenceTableView *)tableView {
  if (!_tableView) {
    _tableView = [[ResidenceTableView alloc] initWithFrame:CGRectMake(0, NavBarHeight, ScreenWidth, ScreenHeight - NavBarHeight-TabBarHeight)];
    [self.view addSubview:_tableView];
  }
  return _tableView;
}

//- (ResidenceScrollView *)contentView {
//  if (!_contentView) {
//    _contentView = [[ResidenceScrollView alloc] initWithFrame:CGRectMake(0, NavBarHeight, ScreenWidth, ScreenHeight - NavBarHeight)];
//    _contentView.clickDelegate = self;
//    [self.view addSubview:_contentView];
//  }
//  return _contentView;
//}

- (void)viewDidLoad {
  [super viewDidLoad];

}

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [self.navigationController setNavigationBarHidden:NO animated:animated];
  [self reloadHeadView];
  [self setStatusBarStyleWhite];
}

- (void)createFields {
  [super createFields];
  self.navigationItem.title = YTLocalizedString(@"账户");
  [self createRightItem];
  
  _dataArray = [[NSMutableArray alloc] init];
  
}

- (void)createViews {
  [super createViews];

}

- (void)loadData {
  [super loadData];
  
  if ([ToolsServer sharedInstance].isLoginApp == NO) {
    return;
  }
  
  _dataArray = @[@"",@"",@"",@""];
  self.tableView.data = _dataArray;
  [self.tableView reloadData];
  
}

- (void)createRightItem {
  
  UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
  [rightButton addTarget:self action:@selector(rightClick) forControlEvents:UIControlEventTouchUpInside];
  
  UIImage *image = [UIImage imageNamed:@"Setting_Tool"];
  [rightButton setBackgroundImage:image forState:UIControlStateNormal];
//  [rightButton setImage:image forState:UIControlStateNormal];
  rightButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
  self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
  
}

- (void)reloadHeadView {
  
  
  if ([ToolsServer sharedInstance].isLoginApp == YES) {
    [self setNavImage:[UIImage imageNamed:@"Home_BgImage"] titleColor:[UIColor whiteColor]];
  } else {
    [self setNavImage:[UIImage imageNamed:@"Oil_head_login"] titleColor:[UIColor whiteColor]];
  }
  
  [self.headerView reloadHead];
  self.tableView.tableHeaderView = self.headerView;
  [self.tableView reloadData];

}

- (void)rightClick {
  
  SettingVC *settingVC = [[SettingVC alloc] init];
  settingVC.hidesBottomBarWhenPushed = YES;
  [self.navigationController pushViewController:settingVC animated:YES];
  
}

#pragma - ResidenceHeadDelegate
- (void)loginClick {

  LoginVC *loginVC = [[LoginVC alloc] init];
  loginVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
  __weak typeof(self) weakSelf = self;
  loginVC.loginSuccessed = ^{
    [weakSelf loadData];
    [weakSelf reloadHeadView];
  };
  
  [self presentViewController:loginVC
                     animated:YES
                   completion:^{
                     
                   }];

  
}

- (void)registClick {
  RegistVC *registVC = [[RegistVC alloc] init];
  registVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
  
  [self presentViewController:registVC
                     animated:YES
                   completion:^{
                     
                   }];

}

@end

